#ifndef SOCKET_H
#define SOCKET_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string>
#include <cstring>
#include <iostream>

class Socket
{
public:
    Socket(int port = 4242, std::string hostname = "localhost");
    void connectSocket();
    int sendMessage(std::string msg);
    int receiveMessage(std::string& msg);
    void setUsername(const std::string name) {username = name;}
    const std::string getUsername() {return username;}

    int operator >> (std::string& msg);
    int operator << (std::string msg);
    int& operator () ();

private:
    int port_number;
    int _mySocket;
    struct sockaddr_in _serverAddress;
    struct hostent* server;
    std::string in_buffer;
    std::string username;

};

#endif // SOCKET_H
